<?php
namespace app\common\tool;

class Kuaishou
{
    private $commomparams;

    private static $instance = null;
    
    private const API_LIST = [
        'GET_ADVERTISER'     => 'https://ad.e.kuaishou.com/rest/openapi/v1/advertiser/info',             //获取广告主账号信息
    ];
    // 禁止被实例化
    // 初始公共Header和公共参数
    public function __construct()
    {
        $this->common_header = [
            "Content-Type: application/json",
        ];    
    }
 
    // 禁止clone
    private function __clone()
    {
        
    }

    // 实例化自己并保存到$instance中，已实例化则直接调用
    public static function getInstance()
    {
        if (empty(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }

    // 获取api列表
    private function getApiUrl()
    {
        return self::API_LIST;
    }

    /**
     * 获取广告主信息
     * @param string access_token
     * @param string advertiser_id
     * 
     * @return array
     */
    public function get_advertiser_info($access_token,$advertiser_id)
    {
        $header = array_merge($this->common_header,[
            "Access-Token: ".$access_token,
        ]);
        $params = [
            'advertiser_id' =>  $advertiser_id
        ];
        $url = $this->getApiUrl()['GET_ADVERTISER'];
        $res = httpRequest($url,json_encode($params),$header);
        return $res;
    }
}